import Vue from 'vue'
import VueRouter from 'vue-router'
// import store from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/layout',
    redirect: '/layout/home',
    component: () => import('@/views/Layout'),
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/Home')
      },
      {
        path: 'profile',
        name: 'profile',
        component: () => import('@/views/Profile')
      },
      {
        path: 'findroom',
        name: 'findroom',
        component: () => import('@/views/FindRoom')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/Login')
  },
  {
    path: '/registe',
    component: () => import('@/views/Registe')
  },
  {
    path: '/city',
    component: () => import('@/views/City')
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('@/views/Detail')
  },
  {
    path: '/map',
    component: () => import('@/views/Map')
  },
  {
    path: '/rent',
    component: () => import('@/views/Rent'),
    children: [
      {
        path: 'add',
        name: 'add',
        component: () => import('@/views/Rent/Add')
      },
      {
        path: 'search',
        component: () => import('@/views/Rent/Search')
      }
    ]
  },
  {
    path: '/favorate',
    component: () => import('@/views/Favorate')
  }
]

const router = new VueRouter({
  routes
})
// // 全局前置路由守卫---初始化的时候被调用、每次路由切换的时候被调用
// router.beforeEach((to, from, next) => {
//   // console.log(store.mapState)
//   console.log(to)
//   // 这里是一个简单的例子
//   // 即判断用户是否进入了需要鉴权的路由下（这里距离为news和message）
//   if (to.path === '/rent' || to.path === '/rent/search' || to.path === '/rent/add' || to.path === '/favorate') {
//     // 如果进入了，那就判断本地是否缓存了信息（这里模拟登录的token)
//     console.log(store.state.LoginState, 12)
//     if (store.state.LoginState === false) {
//       console.log(1)
//       next('/login')
//     } else {
//       next()
//     }
//   } else {
//     // 如果不是，则直接放心即可
//     console.log(1)
//     next()
//   }
// })

export default router
